#pragma once
#include <common.hpp>

namespace zzz{
template<typename T>
class SumCount
{
public:
  SumCount():all_(0), count_(0){}

  const T Sum() const {return all_;}
  const zuint Count() const {return count_;}
  const T Mean() const {return all_/count_;}

  void AddData(const T &p) {
    all_+=p;
    count_++;
  }

  template<typename T1>
  void AddData(const T1& _begin, const T1& _end) {
    for (T1 i=_begin; i!=_end; i++)
      AddData(*i);
  }

  void operator+=(const T &x) {
    AddData(x);
  }

  void operator+=(const vector<T> &x) {
    AddData(x.begin(), x.end());
  }

  void operator+=(const SumCount<T> &x) {
    count_+=x.Count();
    all_+=x.All();
  }

  void Reset() {
    all_ = 0;
    count_ = 0;
  }

private:
  T all_;
  zuint count_;
};
}  // namespace zzz